package application;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;

public class Step1 {
	private HashSet<Integer> nps;
	private HashMap<Integer, Double> contextWeight;
	private HashMap<Integer, HashMap<Integer, Integer>> context2NP;
	public Step1() {
		nps  = new HashSet<Integer>();
		contextWeight = new HashMap<Integer, Double>();
		context2NP = new HashMap<Integer, HashMap<Integer,Integer>>();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		Step1 s = new Step1();
		s.exec(6);
	}

	public void exec(int np) {
		try {
			BufferedReader br = new BufferedReader(new FileReader("6-4.txt"));
			String line;
			
			int i = 0;
			while((line = br.readLine()) != null && i  < 100){
				
				String[] str = line.split("%");
				nps.add(Integer.parseInt(str[0]));
				i++;
			}
			br.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			BufferedReader br2 = new BufferedReader( new FileReader("matrix.txt"));
			String line;
			PrintWriter pw = new PrintWriter("m3.txt");
			
			while((line = br2.readLine()) != null){
				pw.println(line);
				String[] str = line.split("\\s+");
				int n = Integer.parseInt(str[0]);
				
				if(nps.contains(n)){
					int c = Integer.parseInt(str[1]);
					int num = Integer.parseInt(str[2]);
					if(context2NP.containsKey(c)){
						context2NP.get(c).put(n, num);
					}else{
						HashMap<Integer, Integer> npNum = new HashMap<Integer, Integer>();
						npNum.put(n, num);
						context2NP.put(c, npNum	);
							
					}
					
				}
				
				pw.flush();
				pw.close();
				br2.close();
				
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		try {
			BufferedReader br3 = new BufferedReader(new FileReader("6.txt"));
			String line;
			
			while((line = br3.readLine()) != null){
				String[] str = line.split("\\s+");
				int c = Integer.parseInt(str[0]);
				if(context2NP.containsKey(c)){
					contextWeight.put(c, Double.parseDouble(str[1]));
				}
			}
			
			br3.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
